define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/add',
                    edit_url: 'user/user/edit',
                    //del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    import_url: 'user/user/import',
                    kt_url: 'user/user/kt',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false, visible: false},
                        {field: 'pay_mu', title: '充值MU', operate: 'BETWEEN', sortable: true},
                        {field: 'active_mu', title: '活动MU', operate: 'BETWEEN', sortable: true},
                        {field: 'mq', title: 'MQ', operate: 'BETWEEN', sortable: true},
                        // {field: 'usdt_wallet', title: 'USDT钱包', operate: 'BETWEEN', sortable: true},
                        // {field: 'ipfs_wallet', title: 'IPFS钱包', operate: 'BETWEEN', sortable: true},
                        // {field: 'fil_wallet', title: 'FIL3钱包', operate: 'BETWEEN', sortable: true},
                        // {field: 'eth_wallet', title: 'ETH钱包', operate: 'BETWEEN', sortable: true},
                        // {field: 'btc_wallet', title: 'BTC钱包', operate: 'BETWEEN', sortable: true},
                        {field: 'total_mu_achievement', title: '团队业绩MU',operate: false},
                        {field: 'total_mq_achievement', title: '团队业绩MQ',operate: false},
                        // {field: 'total_miner_price', title: '累计购买矿机金额',operate: false},
                        // {field: 'money', title: '个人业绩',operate: false},
                        {field: 'total_mu_reward', title: '购机返佣MU',operate: false},
                        {field: 'total_mq_reward', title: '购机返佣MQ',operate: false},
                        {field: 'total_zt_person', title: '直推人数',operate: false},
                        {field: 'invite_user', title: '推荐人',operate:false},
                        {field: 'invite.invite_user_id', title: '推荐人ID'},
                        {field: 'invite_code', title:'邀请码'},
                        // {field: 'total_invite_reward', title: '邀请奖励',operate: false,visible: false},
                        // {field: 'jointime', title: __('Jointime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false,operate: false},
                        {field: 'verify_status', title: '实名状态', formatter: Table.api.formatter.status, searchList: {0: '未实名', 1: '已实名'}, visible: false},
                        {field: 'active_status', title: '激活状态', formatter: Table.api.formatter.status, searchList: {0: '未激活', 1: '已激活'}, visible: false},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}, visible: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'miner',
                                    title: '空投矿机',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-steam-square',
                                    url: 'user/user/miner',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        miner: function () {
            Controller.api.bindevent();
        },
        import: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});